package controllers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import play.Logger;
import play.mvc.Controller;
import play.vfs.VirtualFile;

public class StaticGAE extends Controller {

	public static void getFile(String file) throws FileNotFoundException {

		VirtualFile vf = VirtualFile.fromRelativePath("/war/static/" + file);

		if (!vf.exists()) {
			notFound();
		} else {
			
			File realFile = vf.getRealFile();
			
			// There are some mime types that are not set correctly
			// we set them manually:
			if (realFile.getAbsolutePath().endsWith(".html")) {				
				response.setContentTypeIfNotSet("text/html");				
			} else if (realFile.getAbsolutePath().endsWith(".css")) {
				response.setContentTypeIfNotSet("text/css");	
				
			}

			InputStream inputStream = new FileInputStream(realFile);
			renderBinary(inputStream);
		}

	}

}
